using System;
using System.Collections.Generic;
using System.Linq;

namespace KTOP.Core.Extensions
{
   public static class ExtEnumerable
    {
        public static IEnumerable<T> One<T>(T value)
        {
            yield return value;
        }

       public static IEnumerable<T> AsEnumerable<T>(this T value)
       {
           return One(value);
       }

       public static IEnumerable<int> OrWith(this IEnumerable< int> source, IEnumerable<int> ie  )
       {
           return source.Zip(ie, (i1, i2) => i1 | i2);
       }

       public static int IndexOfMax<T>(this IEnumerable<T> sequence)
           where T : IComparable<T>
       {
           int maxIndex = -1;
           T maxValue = default(T); // Immediately overwritten anyway

           int index = 0;
           foreach (T value in sequence)
           {
               if (value.CompareTo(maxValue) > 0 || maxIndex == -1)
               {
                   maxIndex = index;
                   maxValue = value;
               }
               index++;
           }
           return maxIndex;
       }
    }
}